package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.ArtType;
import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.ArtTypeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/artType")
public class ArtTypeController {

    @Autowired
    ArtTypeService artTypeService;


    @ApiOperation(value = "新增艺术分类", notes = "新增术分类")
    @ApiImplicitParam(name = "artType", value = "术分类对象", required = true, dataType = "Object")
    @PostMapping
    public Return save(ArtType artType) {
        Return ret = new Return();
        if(artTypeService.insert(artType)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @ApiOperation(value = "修改艺术分类", notes = "修改艺术分类")
    @ApiImplicitParam(name = "activity", value = "艺术分类对象", required = true, dataType = "Object")
    @PutMapping
    public Return<ArtType> update(ArtType artType){
        Return<ArtType> ret=new Return<>();
        if(artTypeService.update(artType)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @ApiOperation(value = "获取艺术分类列表", notes = "获取艺术分类列表")
    @GetMapping
    public Return<List<ArtType>> query(PageInfo pageInfo) {
        Return<List<ArtType>> ret = new Return<>();
        List<ArtType> artTypes = artTypeService.query();
        ret.setData(artTypes);
        return ret;
    }



    @ApiOperation(value = "获取艺术分类", notes = "获取艺术分类")
    @ApiImplicitParam(name = "artTypeId", value = "艺术分类ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{artTypeId}")
    public Return<ArtType> getById(@PathVariable(value = "artTypeId") String artTypeId) {
        Return<ArtType> ret = new Return<>();
        ArtType artType = artTypeService.queryById(artTypeId);
        ret.setData(artType);
        return ret;
    }


    @ApiOperation(value = "删除艺术分类", notes = "删除艺术分类")
    @ApiImplicitParam(name = "artTypeIds", value = "艺术分类ID", required = true, dataType = "String",paramType = "path")
    @DeleteMapping(value = "/{artTypeIds}")
    public Return<ArtType> delete(@PathVariable(value = "artTypeIds") List<String> artTypeIds) {
        Return<ArtType> ret = new Return<>();
        if(artTypeService.deleteMore(artTypeIds)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }
}
